#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setCursor(Qt::BlankCursor);//隐藏鼠标指针

    /*****init config************/
    init_config();

    /*****init advertising*******/
    mplayer = new MPlayer;
    mplayer->setWidthHeight(607, 362);

    /*****init displaytime*******/
    displaytime_init();
    displaytime_setNtp();

    /*****init weather info******/
    weather_timer = new QTimer;
    weather_init();

    /*****init repairs***********/
    repairs_init();

    /*****init monitor***********/
    monitor_init();

    /*****init guard.c***********/
    guard_init();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::startMPlayer()
{
    mplayer->start();
}

void MainWindow::on_pushButton_baoxiu_clicked()
{
    repairs_start();
}

void MainWindow::on_pushButton_jiankong_clicked()
{
    monitor_start();
}

void MainWindow::on_pushButton_entranceGuard_clicked()
{
    guard_start();
}

void MainWindow::init_config()
{
    /*init config file*/
    QString iniFilePath = QCoreApplication::applicationDirPath() + "/config.ini";
    if(!QFile(iniFilePath).exists())
    {
        QMessageBox::critical(nullptr, "ERROR",
                              iniFilePath + " is not exist.");
        qCritical() << iniFilePath + " is not exist.";
    }
    settings = new QSettings(iniFilePath, QSettings::IniFormat);
    settings->setIniCodec("UTF-8");
}
